import sys
import time,datetime
from PySide6.QtCore import QCoreApplication, QObject, QThread, Signal
from PySide6.QtCore import QSettings
from Global import mo


class Worker(QObject):
    # 定义一个信号，用于通知任务完成
    task_finished = Signal()

    def run(self):
        print("Worker thread is running...")
        
        # 发出信号，表示任务完成
        self.task_finished.emit()

if __name__ == "__main__":
    mo.start_time = datetime.datetime.now()
    print("程序开始时间 : ",mo.start_time)
    
    app = QCoreApplication(sys.argv)

    thread = QThread()
    worker = Worker()
    worker.moveToThread(thread)
    thread.started.connect(worker.run)
    worker.task_finished.connect(thread.quit)
    worker.task_finished.connect(app.quit)  # 任务完成后退出应用程序
    thread.start()
    app.exec()
    thread.wait()

    # 读取配置信息
    settings = QSettings("config.ini", QSettings.IniFormat)
    host = settings.value("path/host",type=str)
    port = settings.value("path/port",type=int)
    
    
    
    print("Main thread is exiting.")
    mo.end_time = datetime.datetime.now()
    print("程序结束时间 : ",mo.end_time)
    print("程序运行时间 : ",mo.end_time-mo.start_time)
    